// app.js
import * as $util from './tools/tcglobal';
const {Storage, Tool, API} = $util

App({
  onLaunch() {
    //设置全局变量
    global.$util = $util

    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    this.getSystemInfo();

    // 登录
    // wx.login({
    //   success: res => {
    //     // 发送 res.code 到后台换取 openId, sessionKey, unionId
    //   }
    // })
  },
  globalData: {
    userInfo: null
  },
  getUserInfo(callBack = () => {
  }) { // 获取用户信息
      return API.getUserInfo({}).then((res) => {
          let datas = res.data || {}
          let {

          } = datas
          Storage.setUserAccountInfo(datas)
          try {
              callBack(datas)
          } catch (e) {

          }
          return datas
      }).catch((res) => {
          console.log(res)
      })
  },
  /**
     * 调用微信接口，获取设备信息接口
     */
    getSystemInfo: function (cb) {
      let that = this
      try {
          //调用微信接口，获取设备信息接口
          let res = wx.getSystemInfoSync()
          const {
              model,
              windowWidth,
              screenHeight
          } = res
          if (model.search('iPhone') != -1 &&
              windowWidth >= 375 && screenHeight >= 812 ||
              model.search('iPhone X') != -1)
          {
              res.isIphoneX = true
          } else {
              res.isIphoneX = false
          }
          res.rate = 750 * windowWidth
          Storage.setSysInfo(res)
          that.globalData.systemInfo = res
          typeof cb == "function" && cb(that.globalData.systemInfo)
      }
      catch (e) {

      }
  }
})
